/**
 * 法人渠道参数设置维护 - 编辑页面
 * @author liuw
 * @date 2019/08/30
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            form: '',
            rules: {
                GWAZ001: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                GWAZLEGAL_NAME: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                GWAZACTI: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions: {
                sys_y_n: app.datas_("sys_y_n")
            }
        },
        pageVue,
        callObj,layOpenIndex
    ;

    var Gwas100Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwas100_edit',
                _loadTplsFull: [{
                    dom: 'common_open_window', tpl: 'common/_open_window'
                }]
            }, win);
        },

        editData: function () {
            app.ajax({
                xurl: 'crm/gwas100/edit',
                xdata: vueData.form,
                loading: true,
                okmsg: '法人组织参数修改成功',
                cb: function (result) {
                    if (result.ok) {
                        //同步更新缓存对应的值
                        //callObj.update(result.xdata);
                        app.pageModule('gwas100').reloadTableCurr();
                        layer.close(layOpenIndex);
                    }
                }
            });
        },

        addData: function () {
            app.ajax({
                xurl: 'crm/gwas100/add',
                xdata: vueData.form,
                loading: true,
                okmsg: '法人组织参数保存成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwas100').reloadTableCurr();
                        layer.close(layOpenIndex);
                    }
                }
            });
        },

        _call: function (obj) {
            pageVue.$refs['form'].resetFields();
            layOpenIndex = obj.layOpenIndex;
            if (obj.is_add) {
                vueData.isAdd = true;
                app.ajax({
                    xurl: 'crm/gwas100/getGwaz001',
                    cb: function (result) {
                        if (result.ok) {
                            app.extendUpLow({
                                target: vueData.form,
                                res: {
                                    GWAZ001: result.data.data.GWAZ001,
                                    GWAZACTI: 'Y'
                                },
                                reset: true
                            });
                        }
                    }
                });
            } else {
                vueData.isAdd = false;
                callObj = obj;
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj.data,
                    reset: true
                });
            }

        },
        _ready: function () {
            vueData.form = app.fields_(['base_gwas100'], {GWAZLEGAL_NAME: null});
            pageVue = new Vue({
                el: '#gwas100_edit',
                data: vueData,
                methods: {
                    cancel: function () {
                        layer.close(layOpenIndex);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                if (vueData.isAdd) {
                                    self.addData();
                                } else {
                                    self.editData();
                                }
                            }
                        });
                    },
                    open: function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_sysorg_biz',
                                    columnList: [
                                        {label: 'ID', prop: 'ID', width: '150'},
                                        {label: '归属法人', prop: 'NAME', width: '150'},
                                        {label: '营运中心编号', prop: 'BIZ_CODE', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWAZLEGAL = data.ID;
                                    vueData.form.GWAZLEGAL_NAME = data.NAME;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择法人组织',
                                area: ['600px', '470px']
                            }
                        });
                    }
                },
                watch: {},
                created: function () {
                    self._setEleIsReady('gwas100_edit');
                }
            });
        },

        _lazy: function () {
            this._super();
        }
    });

    return new Gwas100Edit();

});